import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while(n-- > 0){
            int len = in.nextInt();
            int[] arr = new int[len];
            boolean judge = false;
            for(int i = 0; i < len; i++){
                arr[i] = in.nextInt();
                if(arr[i] == 1)
                    judge = true;
            }
            if(judge == true){
                System.out.println("-1");
            }
            else{
                int maxVal = findMaxNum(arr);
                int result = findPrimeNum(maxVal);
                System.out.println(result);
            }
        }
    }
    private static int findMaxNum(int[] arr){
        int len = arr.length;
        int maxVal = arr[0];
        for(int i = 0; i < len; i++){
            if(maxVal < arr[i])
                maxVal = arr[i];
        }
        return maxVal;
    }
    private static int findPrimeNum(int maxVal){
        int tmp = maxVal + 1;
        while(true){
            int k = (int)Math.sqrt(tmp) + 1;
            boolean judge = true;
            for(int i = 2; i <= k; i++){
                if(tmp % i == 0){
                    judge = false;
                    break;
                }
            }
            if(judge == true)
                return tmp;
            else
                tmp++;
        }
    }
}